package com.sun.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sun.pojo.Menu;
import com.sun.pojo.MenuCustom;
import com.sun.service.WebmanageService;
import com.sun.util.ActionUtil;

@Controller
public class WebmanageController {

	@Resource
	private WebmanageService webmanageService;

	@ResponseBody
	@RequestMapping("/listMenu")
	public List<MenuCustom> listMenu() {
		return webmanageService.listMenuTree();
	}

	@ResponseBody
	@RequestMapping("/addMenu")
	public Map<String, Object> addMenu(Menu menu) {
		Integer id = webmanageService.insertMenu(menu);
		if (id != null) {
			return ActionUtil.ajaxSuccess("添加成功", id);
		} else {
			return ActionUtil.ajaxFail("添加失败", null);
		}
	}

	@ResponseBody
	@RequestMapping("/editMenu")
	public Map<String, Object> editMenu(Menu menu) {
		boolean flag = webmanageService.updateMenu(menu);
		if (flag) {
			return ActionUtil.ajaxSuccess("编辑成功", null);
		} else {
			return ActionUtil.ajaxFail("编辑失败", null);
		}
	}
	
	@ResponseBody
	@RequestMapping("/delMenu")
	public Map<String,Object> delMenu(Integer id){
		boolean flag = webmanageService.delMenu(id);
		if (flag) {
			return ActionUtil.ajaxSuccess("删除成功", null);
		} else {
			return ActionUtil.ajaxFail("删除失败", null);
		}
	}
}
